
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>MVC 模式 · classbro-light-weight-web</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Gj">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-prism/prism-tomorrow.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../index.css">
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    
    <link rel="prev" href="views.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    引导
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">src</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../framework.html">
            
                <a href="../framework.html">
            
                    
                    架构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../design.html">
            
                <a href="../design.html">
            
                    
                    设计模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../wechat.html">
            
                <a href="../wechat.html">
            
                    
                    企业微信
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" >
            
                <span>
            
                    
                    账户资料
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="views.html">
            
                <a href="views.html">
            
                    
                    视图层
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="2.4.2" data-path="vuex.html">
            
                <a href="vuex.html">
            
                    
                    MVC 模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >MVC 模式</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="mvc&#x6A21;&#x5F0F;">MVC&#x6A21;&#x5F0F;</h1>
<blockquote>
<p>Vuex&#x3001;Proxy&#x3001;Api</p>
</blockquote>
<h4 id="api&#x6587;&#x4EF6;">Api&#x6587;&#x4EF6;</h4>
<blockquote>
<p>&#x76EE;&#x5F55; <strong>src/api</strong></p>
<p>&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BF7;&#x6C42;</p>
</blockquote>
<h4 id="proxy">Proxy</h4>
<blockquote>
<p>&#x76EE;&#x5F55; <strong>src/proxy/customer/Materials.js</strong></p>
<p>&#x7528;&#x6765;&#x8C03;&#x7528; Api&#x6587;&#x4EF6;&#xFF0C;&#x505A;&#x7C7B;&#x4F3C;&#x6301;&#x4E45;&#x5C42;&#x6570;&#x636E;&#x83B7;&#x53D6;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">import</span> ExceptionBase <span class="token keyword">from</span> <span class="token string">&quot;@/utils/ExceptionBase&quot;</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span>
  ucStudentQueryOne<span class="token punctuation">,</span>
  ucStudentSave<span class="token punctuation">,</span>
  ucStudentQueryTag<span class="token punctuation">,</span>
  ucStudentAddTag<span class="token punctuation">,</span>
<span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;@/api/user&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">class</span> <span class="token class-name">Materials</span> <span class="token keyword">extends</span> <span class="token class-name">ExceptionBase</span> <span class="token punctuation">{</span>
  <span class="token comment">/**
   * &#x6839;&#x636E;&#x7528;&#x6237;wxId&#x67E5;&#x8BE2;&#x7528;&#x6237;&#x8D44;&#x6599;
   * @param {string} wxUserId &#x4F01;&#x4E1A;&#x5FAE;&#x4FE1;&#x7528;&#x6237;id
   */</span>
  <span class="token keyword">async</span> <span class="token function">getUserDetailByWxId</span><span class="token punctuation">(</span><span class="token parameter">wxUserId</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> <span class="token punctuation">{</span> ok<span class="token punctuation">,</span> body <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token keyword">await</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span>ucStudentQueryOne<span class="token punctuation">,</span> wxUserId<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> ok <span class="token operator">?</span> body <span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token comment">/**
   * &#x4FEE;&#x6539;&#x7528;&#x6237;&#x8D44;&#x6599;
   * @param {Object} form &#x8868;&#x5355;
   */</span>
  <span class="token keyword">async</span> <span class="token function">updateUserDetail</span><span class="token punctuation">(</span><span class="token parameter">form</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> <span class="token punctuation">{</span> ok <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token keyword">await</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span>ucStudentSave<span class="token punctuation">,</span> form<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> ok<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token comment">/**
   * &#x83B7;&#x53D6;&#x7528;&#x6237;&#x6807;&#x7B7E;&#x5217;&#x8868;
   * @param {string} wxId &#x4F01;&#x4E1A;&#x5FAE;&#x4FE1;&#x7528;&#x6237;id
   */</span>
  <span class="token keyword">async</span> <span class="token function">getUserTags</span><span class="token punctuation">(</span><span class="token parameter">wxId</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> <span class="token punctuation">{</span> ok<span class="token punctuation">,</span> body <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token keyword">await</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span>ucStudentQueryTag<span class="token punctuation">,</span> <span class="token punctuation">{</span> wxId <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>ok<span class="token punctuation">)</span> <span class="token keyword">return</span> body <span class="token operator">||</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token comment">/**
   * &#x66F4;&#x65B0;/&#x6DFB;&#x52A0;&#x7528;&#x6237;&#x6807;&#x7B7E;
   * @param {string} wxId
   * @param {Array&lt;Object&gt;} tags &#x6807;&#x7B7E;&#x5217;&#x8868;
   */</span>
  <span class="token keyword">async</span> <span class="token function">updateUserTags</span><span class="token punctuation">(</span><span class="token parameter">wxId<span class="token punctuation">,</span> tags</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> <span class="token punctuation">{</span> ok <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token keyword">await</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span>ucStudentAddTag<span class="token punctuation">,</span> <span class="token punctuation">{</span>
      wxId<span class="token punctuation">,</span>
      tags<span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> ok<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token keyword">new</span> <span class="token class-name">Materials</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<h4 id="store">Store</h4>
<blockquote>
<p>&#x76EE;&#x5F55; <strong>src/store/modules/customer_material.js</strong></p>
<p>Vuex</p>
</blockquote>
<h4 id="dispatch">Dispatch</h4>
<blockquote>
<p>&#x76EE;&#x5F55; <strong>src/store/dispatch/index.js</strong>
&#x89C6;&#x56FE;&#x5C42;&#x7EDF;&#x4E00;&#x505A;&#x63A5;&#x53E3;&#x5206;&#x53D1;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">import</span> Material <span class="token keyword">from</span> <span class="token string">&quot;./customer/material&quot;</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> Account <span class="token keyword">from</span> <span class="token string">&quot;./customer/account&quot;</span><span class="token punctuation">;</span>

<span class="token comment">/**
 * &#x5BA2;&#x6237;
 */</span>
<span class="token keyword">export</span> <span class="token keyword">const</span> Customer <span class="token operator">=</span> <span class="token punctuation">{</span>
  <span class="token comment">/**
   * &#x7528;&#x6237;&#x8BE6;&#x60C5;
   */</span>
  Material<span class="token punctuation">,</span>
  <span class="token comment">/**
   * &#x8D26;&#x6237;&#x4FE1;&#x606F;
   */</span>
  Account<span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
</code></pre>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">import</span> Store <span class="token keyword">from</span> <span class="token string">&quot;@/store/index&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  <span class="token comment">/**&#x67E5;&#x8BE2;&#x8D26;&#x6237;&#x4FE1;&#x606F;&#x5217;&#x8868; */</span>
  <span class="token function-variable function">getAccounts</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> Store<span class="token punctuation">.</span><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token string">&quot;customer_material_account/getAccounts&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token comment">/**
   * &#x7ED1;&#x5B9A;&#x7528;&#x6237;-&#x67E5;&#x8BE2;&#x4E1A;&#x52A1;&#x7CFB;&#x7EDF;&#x5BA2;&#x6237;&#x5217;&#x8868;&#x4FE1;&#x606F;
   * @param {string} sysCode db|wx
   * @param {string} key &#x67E5;&#x8BE2;&#x4FE1;&#x606F;
   */</span>
  <span class="token function-variable function">getBindUserList</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> sysCode<span class="token punctuation">,</span> key <span class="token punctuation">}</span></span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span>
    Store<span class="token punctuation">.</span><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token string">&quot;customer_material_account/getBindUserList&quot;</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
      sysCode<span class="token punctuation">,</span>
      key<span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">,</span>

  <span class="token comment">/**
   * &#x7ED1;&#x5B9A;&#x7528;&#x6237;
   * @param {number} childType 1 &#x6587;&#x4E9A;  2&#x5BFC;&#x6BD5;
   * @param {number} ucId
   * @param {string} userId &#x5B50;&#x7CFB;&#x7EDF;&#x5B66;&#x751F;ID
   * @param {string} bindType 1&#x7ED1;&#x5B9A;  2&#x521B;&#x5EFA;   &#x5982;&#x679C;&#x9009;&#x62E9;&#x521B;&#x5EFA; &#x5219;&#x4E0D;&#x9700;&#x8981;&#x9009;&#x62E9;childType
   */</span>
  <span class="token function-variable function">bindUser</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> childType <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">,</span> userId <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">,</span> bindType <span class="token punctuation">}</span></span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span>
    Store<span class="token punctuation">.</span><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token string">&quot;customer_material_account/bindUser&quot;</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
      childType<span class="token punctuation">,</span>
      userId<span class="token punctuation">,</span>
      bindType<span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token comment">/**&#x67E5;&#x8BE2;&#x5E01;&#x79CD;&#x5217;&#x8868; */</span>
  <span class="token function-variable function">getCurrencyList</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span>
    Store<span class="token punctuation">.</span><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token string">&quot;customer_material_account/getCurrencyList&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token comment">/**
   * &#x67E5;&#x8BE2;&#x5386;&#x53F2;&#x5145;&#x503C;&#x8BB0;&#x5F55;
   * @param {string} sysCode db|wx
   * @param {string} userId &#x7528;&#x6237;id
   */</span>
  <span class="token function-variable function">getHistoryRecharge</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">sysCode<span class="token punctuation">,</span> userId</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span>
    Store<span class="token punctuation">.</span><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token string">&quot;customer_material_account/getHistoryRecharge&quot;</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
      sysCode<span class="token punctuation">,</span>
      userId<span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token comment">/**
   * &#x5145;&#x503C;
   * @param {string} current
   * @param {number} money
   * @param {string} thumbUrl
   */</span>
  <span class="token function-variable function">recharge</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">form</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span>
    Store<span class="token punctuation">.</span><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token string">&quot;customer_material_account/recharge&quot;</span><span class="token punctuation">,</span> form<span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token comment">/**
   * &#x5B66;&#x751F;&#x8D26;&#x6237;&#x66F4;&#x65B0;
   */</span>
  <span class="token function-variable function">updateAccount</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">sysCode</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span>
    Store<span class="token punctuation">.</span><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token string">&quot;customer_material_account/updateAccount&quot;</span><span class="token punctuation">,</span> sysCode<span class="token punctuation">)</span><span class="token punctuation">,</span>

  <span class="token comment">/**
   * &#x5BFC;&#x6BD5;|&#x6587;&#x4E9A; &#x8D26;&#x6237;&#x5145;&#x503C;
   * @param {string} sysCode
   * @param {Object} data
   */</span>
  <span class="token function-variable function">createAccount</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">sysCode<span class="token punctuation">,</span> data</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span>
    Store<span class="token punctuation">.</span><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token string">&quot;customer_material_account/createAccount&quot;</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
      sysCode<span class="token punctuation">,</span>
      data<span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">,</span>

  <span class="token comment">/**
   * &#x5BFC;&#x6BD5;|&#x6587;&#x4E9A; &#x8F6C;&#x6C47;
   * @param {string} sysCode
   * @param {Object} data
   */</span>
  <span class="token function-variable function">changeAccount</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">sysCode<span class="token punctuation">,</span> data</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span>
    Store<span class="token punctuation">.</span><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token string">&quot;customer_material_account/changeAccount&quot;</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
      sysCode<span class="token punctuation">,</span>
      data<span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="views.html" class="navigation navigation-prev navigation-unique" aria-label="Previous page: 视图层">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"MVC 模式","level":"2.4.2","depth":2,"previous":{"title":"视图层","level":"2.4.1","depth":2,"path":"src/account/views.md","ref":"src/account/views.md","articles":[]},"dir":"ltr"},"config":{"plugins":["expandable-chapters","-lunr","-search","search-pro","-highlight","prism"],"styles":{"website":"index.css"},"pluginsConfig":{"prism":{"css":["prismjs/themes/prism-tomorrow.css"]},"expandable-chapters":{},"search-pro":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Gj","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"classbro-light-weight-web","language":"zh-hans","gitbook":"3.2.3","description":"效率应用"},"file":{"path":"src/account/vuex.md","mtime":"2020-07-28T06:05:06.861Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-07-28T06:09:20.949Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

